import { defineStore } from 'pinia'
import defaultSettings from '@/setting'

const { title, logo, logoHidden, copyright, showFooter } = defaultSettings;
// 获取本地保存的系统配置
// @ts-ignore
const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || ''
export const useSettingConfig = defineStore('setting', {
  // 返回初始状态的函数
  state: () => {
    return {
      showConfig: false,   //配置面板显示
      collapse: false,    //菜单折叠
      title: title,       
      copyright: copyright,
      logo: logo,         //logo图片地址
      refresh:false,       //内容区刷新
      // 数据持久化结合localstorge
      theme: 'default',
      logoHidden: systemConfig.logoShow === undefined ? logoHidden : systemConfig.logoShow,
      showFooter: systemConfig.footerShow === undefined ? showFooter : systemConfig.footerShow
    }
  },
  actions: {
    changeConfig(data: any) {
      const { key, value } = data
      if (Object.prototype.hasOwnProperty.call(this.$state, key)) {
        this[key] = value;
      }
    }
  },
  getters: {}
})